package com.qiuxi.modules.system.controller;

import com.cartisan.dtos.TreeNode;
import com.qiuxi.modules.system.queries.DepartmentQueryMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.cartisan.responses.ResponseUtil.success;

/**
 * @author oogundam
 * @date 2020/1/10 11:22
 **/
@Api(tags = "TreeNodeController")
@RestController
@RequestMapping("/system/tree")
public class TreeNodeController {

    private final DepartmentQueryMapper mapper;

    public TreeNodeController(DepartmentQueryMapper mapper) {
        this.mapper = mapper;
    }

    @ApiOperation("通过className值获取对应的树")
    @GetMapping("/{className}")
    public ResponseEntity<List<TreeNode>> getDepartmentTree(
            @ApiParam(value = "类名", required = true) @PathVariable String className) {
        if(className.equals("department")) {
            return success(TreeNode.buildTree(mapper.getDepartmentTreeNodes()));
        }
        return success(null);
    }
}
